

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/myblog/img/fluid.png">
  <link rel="icon" href="/myblog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="joelee">
  <meta name="keywords" content="">
  
    <meta name="description" content="后来发现PyTorch包里已经集成有CUDA和cudnn。。。可以不用安装cuda、cudnn。 第一次失败，很正常，最好可以照个快照保存一下状态，方便回滚。 系统：Centos 7 显卡：GRID A100 PyTorch版本：2.1.0 CUDA版本：12.1.1 cuDNN版本：8.9.3 驱动版本：535.104.12  Pytorch、CUDA、cudnn、NVIDIA驱动之间的兼容">
<meta property="og:type" content="article">
<meta property="og:title" content="Centos7 安装PyTorch和GPU环境支持">
<meta property="og:url" content="https://joelee-hit.github.io/joelee-hit.github.io/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/index.html">
<meta property="og:site_name" content="joelee&#39;s blog">
<meta property="og:description" content="后来发现PyTorch包里已经集成有CUDA和cudnn。。。可以不用安装cuda、cudnn。 第一次失败，很正常，最好可以照个快照保存一下状态，方便回滚。 系统：Centos 7 显卡：GRID A100 PyTorch版本：2.1.0 CUDA版本：12.1.1 cuDNN版本：8.9.3 驱动版本：535.104.12  Pytorch、CUDA、cudnn、NVIDIA驱动之间的兼容">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231022212452719.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019144337409.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019144543610.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019104829833.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120541034.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120651413.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120759902.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120904173.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019121055481.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019121357145.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019122624939.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019103233883.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019140049763.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019140141359.png">
<meta property="og:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019140342840.png">
<meta property="article:published_time" content="2023-10-19T06:22:12.000Z">
<meta property="article:modified_time" content="2023-12-28T04:27:42.737Z">
<meta property="article:author" content="joelee">
<meta property="article:tag" content="深度学习">
<meta property="article:tag" content="PyTorch">
<meta property="article:tag" content="GPU">
<meta property="article:tag" content="CUDA">
<meta property="article:tag" content="cuDNN">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://joelee-hit.github.io/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231022212452719.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Centos7 安装PyTorch和GPU环境支持 - joelee&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/myblog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/myblog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/myblog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"joelee-hit.github.io","root":"/myblog/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"UU4TJ0JQzDgf0er5h2RfW8ve-gzGzoHsz","app_key":"px4eIsDZQBJRxIUkt6PCJpNH","server_url":"https://uu4tj0jq.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":true}},"search_path":"/myblog/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/myblog/js/utils.js" ></script>
  <script  src="/myblog/js/color-schema.js" ></script>
  

  

  
    <!-- Google tag (gtag.js) -->
    <script async>
      if (!Fluid.ctx.dnt) {
        Fluid.utils.createScript("https://www.googletagmanager.com/gtag/js?id=", function() {
          window.dataLayer = window.dataLayer || [];
          function gtag() {
            dataLayer.push(arguments);
          }
          gtag('js', new Date());
          gtag('config', '');
        });
      }
    </script>
  

  

  

  

  
    
  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/myblog/">
      <strong>joelee的记事本</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/myblog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Centos7 安装PyTorch和GPU环境支持"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        joelee
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-10-19 14:22" pubdate>
          2023年10月19日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          48 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">Centos7 安装PyTorch和GPU环境支持</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2023年12月28日 中午
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <hr />
<blockquote>
<p>后来发现PyTorch包里已经集成有CUDA和cudnn。。。可以不用安装cuda、cudnn。</p>
<p>第一次失败，很正常，最好可以照个快照保存一下状态，方便回滚。</p>
<p>系统：Centos 7</p>
<p>显卡：GRID A100</p>
<p>PyTorch版本：2.1.0</p>
<p>CUDA版本：12.1.1</p>
<p>cuDNN版本：8.9.3</p>
<p>驱动版本：535.104.12</p>
</blockquote>
<h2
id="pytorchcudacudnnnvidia驱动之间的兼容性">Pytorch、CUDA、cudnn、NVIDIA驱动之间的兼容性</h2>
<p>首先，可以明确，<strong>CUDA(CUDA
Toolkit)、PyTorch、cudnn之间有一定的匹配关系</strong>，不能随便安装。</p>
<h3 id="cuda与驱动">CUDA与驱动</h3>
<p>从<a
target="_blank" rel="noopener" href="https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html">CUDA官网</a>可以看到，<strong>CUDA与驱动的兼容性</strong>如下：</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231022212452719.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231022212452719">
<p>值得注意的是，在CUDA
Toolkit的安装程序中附加了NVIDIA驱动的安装，但是官方并不建议，官方建议到<a
target="_blank" rel="noopener" href="https://www.nvidia.com/drivers">NVIDIA驱动选择界面</a>根据自己的Tesla
GPU来选择驱动。</p>
<p>也就是说，NVIDIA驱动的版本是越新越好。</p>
<blockquote>
<p>另外，可以在<a
target="_blank" rel="noopener" href="https://developer.nvidia.cn/cuda-gpus">这里</a>查看自己显卡的算力。这是<a
target="_blank" rel="noopener" href="https://www.nvidia.com/en-us/data-center/a100/">A100显卡</a>的。</p>
<p>关于CUDA向后兼容性的理解，可以看看<a
target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/459431437">这篇文章</a>。</p>
</blockquote>
<h3 id="cudnn与cuda">cudnn与CUDA</h3>
<p><strong>cuDNN</strong>是用于深度神经网络的GPU加速库，相当于是对CUDA的补充。可以在<a
target="_blank" rel="noopener" href="https://developer.nvidia.com/rdp/cudnn-download">cuDNN官网</a>选择与已安装的CUDA版本对应的下载。</p>
<blockquote>
<p>值得注意的是，tensorflow-gpu对cuDNN的版本也有一定限制，可以在<a
target="_blank" rel="noopener" href="https://tensorflow.google.cn/install/source#tested_build_configurations">这里</a>查看。就是不知道PyTorch有没有？！在<a
target="_blank" rel="noopener" href="https://pytorch.org/get-started/locally/#linux-prerequisites">这里</a>可以看到CUDA只要满足PyTorch要求的最低版本即可，越新越好。</p>
<p>To install PyTorch via Anaconda, and you do have a CUDA-capable
system, in the above selector, choose OS: Linux, Package: Conda and the
CUDA version suited to your machine. Often, the latest CUDA version is
better. Then, run the command that is presented to you.</p>
</blockquote>
<h3 id="pytorch与cudapython">PyTorch与CUDA、Python</h3>
<p>在<a
target="_blank" rel="noopener" href="https://pytorch.org/">PyTorch</a>官网上，可以看到Pytorch对于不同版本的CUDA有不同的安装指令。</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019144337409.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019144337409">
<p>在<a
target="_blank" rel="noopener" href="https://pytorch.org/get-started/locally/">PyTorch的get-started界面</a>可以看到PyTorch对OS发行版、Python版本($$3.8)都有一定要求，也有验证是否能使用GPU的方法。</p>
<p>总结，<strong>不同版本的PyTorch要求不同的最低版本的CUDA和不同版本的Python，而CUDA又决定该选择什么版本的cuDNN</strong>。</p>
<h2 id="准备工作">准备工作</h2>
<h3 id="禁用nouveau">禁用nouveau</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 法1</span><br><span class="hljs-comment"># 查看系统自带的驱动：</span><br>lsmod | grep nouveau<br><br><span class="hljs-comment"># 编辑如下文件：</span><br>sudo vi /usr/lib/modprobe.d/dist-blacklist.conf<br><span class="hljs-comment"># 然后在最后添加如下内容：</span><br>blacklist nouveau<br>options nouveau modeset=0<br><br><span class="hljs-comment"># 法2</span><br><span class="hljs-comment"># 有的路径是/etc/modprobe.d/blacklist.conf</span><br>sudo vi /usr/lib/modprobe.d/blacklist-nouveau.conf<br><span class="hljs-comment"># 然后在最后添加如下内容：</span><br>blacklist nouveau<br>options nouveau modeset=0<br>sudo modprobe -r nouveau<br>reboot<br><br><span class="hljs-comment"># 法3 成功</span><br>lsmod | grep nouveau<br>sudo vi /etc/modprobe.d/blacklist-nouveau.conf<br>sudo dracut --force<br>reboot<br></code></pre></td></tr></table></figure>
<h3 id="查看是否有显卡">查看是否有显卡</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs bash">lspci | grep VGA<br><br><span class="hljs-comment"># 返回</span><br>00:02.0 VGA compatible controller: Red Hat, Inc. QXL paravirtual graphic card (rev 04)<br></code></pre></td></tr></table></figure>
<h3 id="查看显卡型号">查看显卡型号</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs bash">lspci | grep NVIDIA<br><br><span class="hljs-comment"># 返回</span><br>00:05.0 3D controller: NVIDIA Corporation GA100 [GRID A100 PCIe 40GB] (rev a1)<br>00:06.0 3D controller: NVIDIA Corporation GA100 [GRID A100 PCIe 40GB] (rev a1)<br></code></pre></td></tr></table></figure>
<h3 id="查看cuda是否安装">查看cuda是否安装</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">nvcc -V<br><span class="hljs-built_in">ls</span> /usr/local | grep cuda<br></code></pre></td></tr></table></figure>
<h3 id="查看驱动是否安装">查看驱动是否安装</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">nvidia-smi<br><span class="hljs-built_in">ls</span> /proc/driver | grep nvidia<br></code></pre></td></tr></table></figure>
<h3 id="检查os发行版是否支持">检查OS发行版是否支持</h3>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019144543610.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019144543610">
<p>检查链接：<a
target="_blank" rel="noopener" href="https://pytorch.org/get-started/locally/#supported-linux-distributions">这里</a></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 查看内核和发行版</span><br><span class="hljs-built_in">uname</span> -a &amp;&amp; <span class="hljs-built_in">cat</span> /etc/redhat-release<br><br><span class="hljs-comment"># 返回</span><br>Linux n1 3.10.0-1160.99.1.el7.x86_64 <span class="hljs-comment">#1 SMP Wed Sep 13 14:19:20 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux</span><br>CentOS Linux release 7.9.2009 (Core)<br></code></pre></td></tr></table></figure>
<h3 id="检查python版本">检查Python版本</h3>
<p>Python 3.8 or greater。</p>
<h2 id="下载并安装好相应程序文件">下载并安装好相应程序文件</h2>
<h3 id="nvidia驱动">NVIDIA驱动</h3>
<p><strong>驱动越新越好</strong>。</p>
<p><strong>安装基础rpm依赖包</strong>：安装Nvidia驱动所需要的依赖包为kernel-devel、gcc、dkms。验证cudn，编译并运行验证Sample代码所需要的依赖包为gcc-c++。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 验证当前服务器内核版本是否与yum提供的kernel-devel版本是否一致</span><br><span class="hljs-built_in">uname</span> -r &amp;&amp; yum list | grep kernel-devel<br><span class="hljs-comment"># 不一致,更换内核版本</span><br>sudo yum install kernel-devel-$(<span class="hljs-built_in">uname</span> -r)<br><br>sudo yum install gcc dkms<br></code></pre></td></tr></table></figure>
<p><a
target="_blank" rel="noopener" href="https://www.nvidia.com/download/index.aspx?lang=en-us">选择界面</a>，我选择</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019104829833.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019104829833">
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">wget https://us.download.nvidia.cn/tesla/535.104.12/NVIDIA-Linux-x86_64-535.104.12.run<br></code></pre></td></tr></table></figure>
<p>安装过程中允许DMKS。</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120541034.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019120541034">
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120651413.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019120651413">
<p>选择No。</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120759902.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019120759902">
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019120904173.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019120904173">
<p>选择Yes。</p>
<p><strong>验证</strong>：</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019121055481.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019121055481">
<h3 id="cuda">CUDA</h3>
<p><a target="_blank" rel="noopener" href="https://developer.nvidia.com/cuda-toolkit-archive">CUDA
Toolkit 选择界面</a>，我选择<a
target="_blank" rel="noopener" href="https://developer.nvidia.com/cuda-12-1-1-download-archive?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=CentOS&amp;target_version=7&amp;target_type=runfile_local">CUDA12.1.1</a>。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">wget https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_530.30.02_linux.run<br>sudo sh cuda_12.1.1_530.30.02_linux.run<br></code></pre></td></tr></table></figure>
<p>安装过程中注意，取消driver的选择，安装好之后</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs bash">vi ~/.bashrc<br><span class="hljs-comment"># 最后加入</span><br><span class="hljs-built_in">export</span> CUDA_HOME=/usr/local/cuda<br><span class="hljs-built_in">export</span> LD_LIBRARY_PATH=<span class="hljs-variable">$&#123;CUDA_HOME&#125;</span>/lib64<span class="hljs-variable">$&#123;LD_LIBRARY_PATH+:<span class="hljs-variable">$&#123;LD_LIBRARY_PATH&#125;</span>&#125;</span><br><span class="hljs-built_in">export</span> PATH=<span class="hljs-variable">$&#123;CUDA_HOME&#125;</span>/bin:<span class="hljs-variable">$PATH</span><br><br><span class="hljs-comment"># 执行</span><br><span class="hljs-built_in">source</span> ~/.bashrc<br><br><span class="hljs-comment"># 验证</span><br>nvcc -V<br></code></pre></td></tr></table></figure>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019121357145.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019121357145">
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019122624939.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019122624939">
<p>没用的用space键或Enter取消。</p>
<p>完成后：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs bash">===========<br>= Summary =<br>===========<br><br>Driver:   Not Selected<br>Toolkit:  Installed <span class="hljs-keyword">in</span> /usr/local/cuda-12.1/<br><br>Please make sure that<br> -   PATH includes /usr/local/cuda-12.1/bin<br> -   LD_LIBRARY_PATH includes /usr/local/cuda-12.1/lib64, or, add /usr/local/cuda-12.1/lib64 to /etc/ld.so.conf and run ldconfig as root<br><br>To uninstall the CUDA Toolkit, run cuda-uninstaller <span class="hljs-keyword">in</span> /usr/local/cuda-12.1/bin<br>***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 530.00 is required <span class="hljs-keyword">for</span> CUDA 12.1 functionality to work.<br>To install the driver using this installer, run the following <span class="hljs-built_in">command</span>, replacing &lt;CudaInstaller&gt; with the name of this run file:<br>    sudo &lt;CudaInstaller&gt;.run --silent --driver<br><br>Logfile is /var/log/cuda-installer.log<br></code></pre></td></tr></table></figure>
<h3 id="cudnn">cudnn</h3>
<p>可以在<a
target="_blank" rel="noopener" href="https://developer.nvidia.com/rdp/cudnn-archive">这里</a>挑选。我选择<a
target="_blank" rel="noopener" href="https://developer.nvidia.com/rdp/cudnn-archive#a-collapse893-120">Download
cuDNN v8.9.3 (July 11th, 2023), for CUDA 12.x</a>。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 链接过长，所以使用-O参数和双引号修饰符，发现tm的下载的竟然是网页？？可能链接有时效性</span><br>wget -O cudnn-linux-x86_64-8.9.3.28_cuda12-archive.tar.xz <span class="hljs-string">&quot;https://developer.download.nvidia.cn/compute/cudnn/secure/8.9.3/local_installers/12.x/cudnn-linux-x86_64-8.9.3.28_cuda12-archive.tar.xz?HMC_802VfF0fBq1s9Rj92E7-S3swVruOO85p_xb0yhmFzp78Ee3OCWG-3AyVJp3M_HUllCiwyddhAkw-LSOwQlvt1SSOvUipIyeXSr1pQDokwKjWAyVMqBu8nVf65zrZAAH1Sd6MvndL2WdKEglsu5OW5PRKnRe7atBz9rDCEqCO3rQzOVwDAvJ3XCySNv864H1kOJOd4aVYbWI0HbQ6QY4=&amp;t=eyJscyI6InJlZiIsImxzZCI6IlJFRi1kb2NzLm52aWRpYS5jb20vIn0=&quot;</span><br><br><span class="hljs-comment"># 直接到直链下载 https://developer.download.nvidia.com/compute/redist/cudnn</span><br><span class="hljs-comment"># 但是直链仅支持v8.8</span><br><br><span class="hljs-comment"># 法1：去https://developer.nvidia.com/rdp/cudnn-archive获取直链,在其失效之前赶紧下载</span><br><br><span class="hljs-comment"># 也可以用scp传输</span><br>scp -P 端口 ./本机某文件 用户名@远程主机名:远程主机某目录<br></code></pre></td></tr></table></figure>
<p>安装过程：https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#installlinux-tar</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash">tar -xvf cudnn-linux-<span class="hljs-variable">$arch</span>-8.x.x.x_cudaX.Y-archive.tar.xz<br><br><span class="hljs-comment"># 安装</span><br>sudo <span class="hljs-built_in">cp</span> cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include <br>sudo <span class="hljs-built_in">cp</span> -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64 <br>sudo <span class="hljs-built_in">chmod</span> a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*<br></code></pre></td></tr></table></figure>
<h3 id="pytorch">PyTorch</h3>
<p><a target="_blank" rel="noopener" href="https://pytorch.org/">PyTorch</a>官网</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019103233883.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019103233883">
<blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># conda</span><br>conda create -n <span class="hljs-built_in">test</span> python=3.9<br>conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia<br><br><span class="hljs-comment"># pip</span><br>pip3 install torch torchvision torchaudio<br></code></pre></td></tr></table></figure>
</blockquote>
<h2 id="验证">验证</h2>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> torch<br>x = torch.rand(<span class="hljs-number">5</span>, <span class="hljs-number">3</span>)<br><span class="hljs-built_in">print</span>(x)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;cuda是否可用: &quot;</span>,torch.cuda.is_available())<br><br><span class="hljs-comment"># 输出应该是</span><br>tensor([[<span class="hljs-number">0.3380</span>, <span class="hljs-number">0.3845</span>, <span class="hljs-number">0.3217</span>],<br>        [<span class="hljs-number">0.8337</span>, <span class="hljs-number">0.9050</span>, <span class="hljs-number">0.2650</span>],<br>        [<span class="hljs-number">0.2979</span>, <span class="hljs-number">0.7141</span>, <span class="hljs-number">0.9069</span>],<br>        [<span class="hljs-number">0.1449</span>, <span class="hljs-number">0.1132</span>, <span class="hljs-number">0.1375</span>],<br>        [<span class="hljs-number">0.4675</span>, <span class="hljs-number">0.3947</span>, <span class="hljs-number">0.1426</span>]])<br>true<br></code></pre></td></tr></table></figure>
<h2 id="更新一下">更新一下</h2>
<p><strong>因为pytorch自带cuda和cudnn</strong>，你只需要准备支持高于这个cuda版本的显卡驱动就可以了。（不过这个cuda只包含给pytorch用的库函数，不包括cuda
toolchain，比如nvcc等等，如果需要完整的cuda还是要自己装）。。。。。</p>
<p>进入pytorch的安装目录就可以看到，pytorch在编译的时候已经把cuda的库静态链接到了自己的库里，用conda或者pip安装的包已经打包好这些了。</p>
<p>test环境里的包：</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019140049763.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019140049763">
<p>nvidia文件夹里：</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019140141359.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019140141359">
<p>torch的lib目录：</p>
<img src="/myblog/2023/10/19/Centos7-%E5%AE%89%E8%A3%85PyTorch%E5%92%8CGPU%E7%8E%AF%E5%A2%83%E6%94%AF%E6%8C%81/image-20231019140342840.png" srcset="/myblog/img/loading.gif" lazyload class="" title="image-20231019140342840">
<p>链接：https://blog.csdn.net/qq_36944952/article/details/109460760</p>
<h2 id="工具">工具</h2>
<h3 id="清理">清理</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 包含了GUI，所以不喜欢</span><br>sudo yum install bleachbit-cli<br>bleachbit --list  <span class="hljs-comment"># 列出可用的清理项目和应用程序选项</span><br>bleachbit --clean system.cache system.tmp <span class="hljs-comment"># 例如</span><br><br><span class="hljs-comment"># 原生命令</span><br>sudo yum clean all  <span class="hljs-comment"># 清除缓存的yum包</span><br>sudo journalctl --vacuum-time=3d  <span class="hljs-comment"># 清除日志</span><br><br><span class="hljs-comment"># conda清理</span><br>conda clean -p<br>conda clean -t<br>conda clean -y -a<br><br><span class="hljs-comment"># pip清理</span><br>pip cache purge<br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/myblog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/" class="category-chain-item">深度学习</a>
  
  
    <span>></span>
    
  <a href="/myblog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E5%8A%A8%E6%89%8B%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83/" class="category-chain-item">动手搭建环境</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/myblog/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/" class="print-no-link">#深度学习</a>
      
        <a href="/myblog/tags/PyTorch/" class="print-no-link">#PyTorch</a>
      
        <a href="/myblog/tags/GPU/" class="print-no-link">#GPU</a>
      
        <a href="/myblog/tags/CUDA/" class="print-no-link">#CUDA</a>
      
        <a href="/myblog/tags/cuDNN/" class="print-no-link">#cuDNN</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Centos7 安装PyTorch和GPU环境支持</div>
      <div>https://joelee-hit.github.io/joelee-hit.github.io/2023/10/19/Centos7-安装PyTorch和GPU环境支持/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>joelee</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年10月19日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年12月28日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/myblog/2023/12/29/bochs-linux0-12-%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" title="bochs-linux0-12-环境搭建">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">bochs-linux0-12-环境搭建</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"UU4TJ0JQzDgf0er5h2RfW8ve-gzGzoHsz","appKey":"px4eIsDZQBJRxIUkt6PCJpNH","path":"window.location.pathname","placeholder":null,"avatar":"robohash","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/myblog/js/events.js" ></script>
<script  src="/myblog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/myblog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script defer src="/myblog/js/leancloud.js" ></script>

  <script  src="/myblog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/myblog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
